<?php
require_once "lib/eclipse_exdr_parser.php";
require_once "lib/eclipse_socket.php";

$host = "localhost";
$port = 9000;

// instance of the logic server socket for EXDR term exchange
$logicServer = new EclipseSocket($host, $port);

/**
 * If you want to log EXDR communication, uncomment the next two lines
 */
//$logger = &Log::factory('file', 'exdrProtocol.log', 'Example');
//$this->logicServer->setLogger($logger);

// assemble local OO representation of the goal to be issued to the logic server
$goal = new Predicate('allperms', array(array('h', 'o', 'm', 'e'), null));

// issue the goal over socket connection an wait the response EXDR_EXDRTerm
$term = $logicServer->rpcGoal($goal->toEXDRTerm());

// get an OO representation of the response term (a Predicate)
$pred = $term->getTerm()->getObject();

// we are interested to the second argument (the list of permutations)
// of the predicate which is a List, so will be parsed as an array.
$solutionList = $pred->getArg(1);

$out = "<pre>";

// iterate over the list of solutions
foreach($solutionList as $s){
	// iterate over the elements of a solution (permutation)
	$out .= "{";
	foreach($s as $e){
		$out .= $e;
	}
	$out .= "}\n";
}
$out .= "</pre>";
?>
<html>
	<head>
		<title>ECLiPSe logic server query example</title>
	</head>
	<body>
		<?php echo $out ?>
	</body>
</html>